<?php

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

class SettingRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'title' => 'required',
            'name' => [
                'required',
                'regex:/^[a-zA-Z][a-zA-Z0-9_]*$/',
                'unique:settings,name,' . $this->route('id'),
            ],
            'type' => 'required',
            'group' => 'integer',
            'sort' => 'integer',
        ];
        return $rules;
    }

    public function messages()
    {
        return [
            'title.required' => '请填写标题',
            'name.required' => '请填写名称',
            'name.regex' => '名称格式不正确',
            'name.unique' => '名称已被占用',
            'type.required' => '请选择类型',
            'group.integer' => '请选择分组',
            'sort.integer' => '排序序号只能为数字',
        ];
    }

}
